package eu.telecombretagne.rsm.gui.frames.panels;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import eu.telecombretagne.rsm.gui.NameConsts;

public class ChoiceSettingsPanel extends JPanel {
	
	private static final long serialVersionUID = -6813067781755456433L;
	
	private JRadioButton globalSettingButton;
	private JRadioButton detailedSettingButton;
	private ButtonGroup group;
	
	/**
	 * The constructor of the ChoiceSettingsPanel.
	 * @param pActionListener A listener for this panel.
	 */
	public ChoiceSettingsPanel(ActionListener pActionListener){
		setLayout(new GridLayout(1, 2));
		setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NameConsts.SETTINGSCHOICE));
		
		globalSettingButton = new JRadioButton(NameConsts.SIMPLIFIED);
		globalSettingButton.setActionCommand("rdBtnSimplified");
		globalSettingButton.addActionListener(pActionListener);
		
		detailedSettingButton = new JRadioButton(NameConsts.DETAILED);
		detailedSettingButton.setActionCommand("rdBtnDetailed");
		detailedSettingButton.addActionListener(pActionListener);
		
		add(globalSettingButton);
		add(detailedSettingButton);
		
		group = new ButtonGroup();
		group.add(globalSettingButton);
		group.add(detailedSettingButton);
		
		globalSettingButton.doClick();
	}
	
	/**
	 * Checks whether global settings are enabled.
	 * @return Returns <i>true</i> if global settings are enabled.
	 */
	public Boolean isGlobalSettingsSelected(){
		return group.isSelected(globalSettingButton.getModel());
	}
	
	/**
	 * Sets panel as locked.
	 * @param pLocked If set to <i>true</i> the panel is going to be locked.
	 */
	public void setPanelLocked(Boolean pLocked){
		Component[] components = this.getComponents();
		
		for(int i = 0; i < components.length; i++){
			components[i].setEnabled(!pLocked);
		}
	}
}